package cn.cvs.servlet;

import cn.cvs.dao.sysUser.CardMapper;
import cn.cvs.pojo.Card;
import cn.cvs.service.CardService;
import cn.cvs.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/ListServlet")
public class ListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        CardService cardService = new CardService();

        String stoPageSize = request.getParameter("pageSize");
        String stoPageNo = request.getParameter("pageNo");

        int pageNo=1;
        int pageSize = 6;
        if (stoPageNo !=null){
            pageNo = Integer.parseInt(request.getParameter("pageNo"));
        }
        if (stoPageSize !=null){
            pageSize = Integer.parseInt(request.getParameter("pageSize"));
        }
        int pageBegin = (pageNo-1)*pageSize;

        List<Card> list = cardService.list(pageBegin, pageSize);
        request.setAttribute("list",list);
        request.setAttribute("pageNo",pageNo);
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
}
